package com.geeguo.ebuilder.operation.controller.tenant.tenantinfo;

import com.geeguo.ebuilder.core.common.action.ActionResult;
import com.geeguo.ebuilder.operation.business.tenant.tenantinfo.model.TenantInfoVO;
import com.geeguo.ebuilder.operation.business.tenant.tenantinfo.service.TenantInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "租户信息")
@RestController
public class TenantInfoController {

    @Autowired
    private TenantInfoService tenantInfoService;

    @Operation(summary = "查询启用的租户列表")
    @PostMapping("/tenant/tenantInfo/listValid")
    public ActionResult<List<TenantInfoVO>> listValid() {
        return ActionResult.success(tenantInfoService.listValid());
    }

    @Operation(summary = "根据租户编码查询租户")
    @GetMapping("/tenant/tenantInfo/getByCode/{code}")
    public ActionResult<TenantInfoVO> getByCode(@PathVariable("code") String code) {
        return ActionResult.success(tenantInfoService.getByCode(code));
    }

    @Operation(summary = "根据租户域名查询租户")
    @GetMapping("/tenant/tenantInfo/getByDomain/{domain}")
    public ActionResult<TenantInfoVO> getByDomain(@PathVariable("domain") String domain) {
        return ActionResult.success(tenantInfoService.getByDomain(domain));
    }
}